package com.org.zp.ctrl.payquery;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.org.base.ctrl.ActivityTaskManager;
import com.org.base.ctrl.BaseActivity;
import com.org.base.util.HttpUtils;
import com.org.zp.R;
import com.org.zp.app.RecApp;

public class PayqueryActivity extends BaseActivity {

	private RelativeLayout pay_query_name;// 职位名称
	private TextView pay_query_name_txt;// 职位名称

	private RelativeLayout pay_query_type_main;// 行业
	private TextView pay_query_type;// 行业

	private RelativeLayout pay_query_address_main;// 工作地点
	private TextView pay_query_address_txt;// 工作地点

	private EditText keyword;// 关键字 p_keyword_title

	private RelativeLayout pay_query_positiontype_main;// 职位性质
	private TextView pay_query_positiontype_txt;// 职位性质

	private RelativeLayout pay_query_companysize_main;// 公司规模
	private TextView pay_query_companysize_txt;// 公司规模

	private TextView title;
	private Button back_btn, top_right_btn;
	private Button search_button;
	private RecApp mApp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.payquery);

		if (!(ActivityTaskManager.getInstance()
				.containsName("PayqueryActivity"))) {
			ActivityTaskManager.getInstance().putActivity("PayqueryActivity",
					this);
		}
		
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

		mApp = getMyApplication();
		title = (TextView) findViewById(R.id.headTitle);
		back_btn = (Button) findViewById(R.id.back);
		back_btn.setText("  返回");
		back_btn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ActivityTaskManager.getInstance().removeActivity(
						"PayqueryActivity");
			}
		});

		top_right_btn = (Button) findViewById(R.id.top_right_button);
		top_right_btn.setVisibility(View.GONE);
		search_button = (Button) findViewById(R.id.pay_query_bt);
		pay_query_name = (RelativeLayout) findViewById(R.id.pay_query_name);//
		pay_query_type_main = (RelativeLayout) findViewById(R.id.pay_query_type_main);//
		pay_query_address_main = (RelativeLayout) findViewById(R.id.pay_query_address_main);//
		pay_query_positiontype_main = (RelativeLayout) findViewById(R.id.pay_query_positiontype_main);// 公司性质
		pay_query_companysize_main = (RelativeLayout) findViewById(R.id.pay_query_companysize_main);// 公司规模
		pay_query_name_txt = (TextView) findViewById(R.id.pay_query_name_txt);
		pay_query_type = (TextView) findViewById(R.id.pay_query_type_txt);
		pay_query_address_txt = (TextView) findViewById(R.id.pay_query_address_txt);
		pay_query_positiontype_txt = (TextView) findViewById(R.id.pay_query_positiontype_txt);
		pay_query_companysize_txt = (TextView) findViewById(R.id.pay_query_companysize_txt);
		keyword = (EditText) findViewById(R.id.pay_query_keyword_txt);// 关键字
		keyword.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				// mApp.keyword = keyword.getText().toString();
			}
		});
		title.setText("薪酬查询");
		initCompents();
		// 搜索按钮
		search_button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				if (!(HttpUtils.checkNetwork(PayqueryActivity.this, true))) {
					return;
				}

				if (keyword.getText().toString().equals("")) {
					Toast toast = Toast.makeText(getApplicationContext(),
							"请输入期望月薪！", Toast.LENGTH_SHORT);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.show();
					return;
				}

				Intent intent = new Intent(PayqueryActivity.this,
						PayQuryResultActivity.class);
				intent.putExtra("address", pay_query_address_txt.getText()
						.toString());
				intent.putExtra("positionname", pay_query_name_txt.getText()
						.toString());
				intent.putExtra("hangye", pay_query_type.getText().toString());
				intent.putExtra("positiontype", pay_query_positiontype_txt
						.getText().toString());
				intent.putExtra("companysize", pay_query_companysize_txt
						.getText().toString());
				intent.putExtra("key", keyword.getText().toString());
				startActivity(intent);
			}
		});
	}

	private void initCompents() {

		if (null != mApp.keyword && !"".equals(mApp.keyword)) {
			keyword.setText(mApp.keyword);
		}

		if (null != mApp.hPayName.get("position_name_second")
				&& !mApp.hPayName.get("position_name_second").equals(""))
			pay_query_name_txt.setText(mApp.hPayName
					.get("position_name_second"));
		pay_query_name_txt.setTextColor(Color.BLACK);
		if (null != mApp.hPayName.get("position_hangye")
				&& !mApp.hPayName.get("position_hangye").equals(""))
			pay_query_type.setText(mApp.hPayName.get("position_hangye"));
		pay_query_type.setTextColor(Color.BLACK);
		if (null != mApp.hPayName.get("position_address_second")
				&& !mApp.hPayName.get("position_address_second").equals(""))
			pay_query_address_txt.setText(mApp.hPayName
					.get("position_address_second"));
		pay_query_address_txt.setTextColor(Color.BLACK);
		if (null != mApp.hPayName.get("position_positiontype")
				&& !mApp.hPayName.get("position_positiontype").equals(""))
			pay_query_positiontype_txt.setText(mApp.hPayName
					.get("position_positiontype"));
		pay_query_positiontype_txt.setTextColor(Color.BLACK);
		if (null != mApp.hPayName.get("position_companysize")
				&& !mApp.hPayName.get("position_companysize").equals(""))
			pay_query_companysize_txt.setText(mApp.hPayName
					.get("position_companysize"));
		pay_query_companysize_txt.setTextColor(Color.BLACK);

		pay_query_positiontype_main.setOnClickListener(listener);
		pay_query_companysize_main.setOnClickListener(listener);
		pay_query_name.setOnClickListener(listener);
		pay_query_type_main.setOnClickListener(listener);
		pay_query_address_main.setOnClickListener(listener);

		pay_query_positiontype_main.setVisibility(View.VISIBLE);
		pay_query_companysize_main.setVisibility(View.VISIBLE);
		pay_query_type_main.setVisibility(View.VISIBLE);
	}

	private View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent intent = null;
			switch (v.getId()) {
			case R.id.pay_query_name:// 职位名称

				intent = new Intent(PayqueryActivity.this, SearchPayList.class);
				intent.putExtra("type", "position_name");
				startActivity(intent);
				break;
			case R.id.pay_query_type_main:// 行业
				intent = new Intent(PayqueryActivity.this, SearchPayList.class);
				intent.putExtra("type", "position_hangye");
				startActivity(intent);
				break;
			case R.id.pay_query_address_main: // 工作地点
				intent = new Intent(PayqueryActivity.this, SearchPayList.class);
				intent.putExtra("type", "position_address");
				startActivity(intent);
				break;
			case R.id.pay_query_positiontype_main:// 职位性质
				intent = new Intent(PayqueryActivity.this, SearchPayList.class);
				intent.putExtra("type", "position_positiontype");
				startActivity(intent);
				break;
			case R.id.pay_query_companysize_main:// 公司规模
				intent = new Intent(PayqueryActivity.this, SearchPayList.class);
				intent.putExtra("type", "position_companysize");
				startActivity(intent);
				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			ActivityTaskManager.getInstance().removeActivity(
					"PayqueryActivity");
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

}
